<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <title>添加教室</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../static/layuimini/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../static/layuimini/css/public.css" media="all">
    <style>
        .layui-form-item .layui-input-company {
            width: auto;
            padding-right: 10px;
            line-height: 38px;
        }
    </style>

    <script src="../../../static/layuimini/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
    <script src="../../../static/layuimini/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
    <script src1="http://local.res.layui.com/layui/release/laydate/dist/laydate.js" charset="utf-8"></script>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <div class="layui-form layuimini-form" lay-filter="first">
            <div class="layui-form-item">
                <label class="layui-form-label required">楼区</label>
                <div class="layui-input-block">
                    <select name="building" lay-verify="required" lay-verType="tips" lay-filter="building"
                            id="building">
                        <option value="">请选择楼区</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">教室名称</label>
                <div class="layui-input-block">
                    <input type="text" name="classroomName" lay-verify="required" lay-reqtext="教室名称不能为空"
                           placeholder="请输入教室名称"
                           value="" class="layui-input" id="classroomName">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">容量</label>
                <div class="layui-input-block">
                    <input type="number" name="capacity" lay-verify="required" lay-reqtext="容量不能为空" placeholder="请输入容量"
                           value="" class="layui-input" id="capacity">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">场地类别</label>
                <div class="layui-input-block">
                    <select name="classroomType" lay-verify="required" lay-verType="tips" lay-filter="classroomType"
                            id="classroomType">
                        <option value="">请选择场地类别</option>
                        <option value="实验教室">实验教室</option>
                        <option value="理论教室">理论教室</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">保存</button>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    layui.use(['form', 'miniTab'], function () {
        var form = layui.form,
            layer = layui.layer,
            miniTab = layui.miniTab,
            $ = layui.jquery;

        //初始化楼号下拉框
        $.get("/getBuilding", function (data) {
            $.each(data, function (index, element) {
                $("#building").append("<option value='" + element.buildingName + "'>" + element.buildingName + "</option>");
            });
            layui.form.render('select');
        }, "json");

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            let classroomId = $("#classroomId").val();
            let building = $("#building").val();
            let classroomName = $("#classroomName").val();
            let classroomType = $("#classroomType").val();
            let capacity = $("#capacity").val();

            $.get("/addClassroom", {
                // classroomId: classroomId,
                building: building,
                classroomName: classroomName,
                classroomType: classroomType,
                capacity: capacity
            }, function (data) {
                if (data == "success") {
                    layer.msg('教室添加成功', {
                        icon: 1,
                        time: 1000, //1秒关闭（如果不配置，默认是3秒）
                    }, function () {
                        // parent.layer.closeAll('iframe');
                        let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                        parent.window.location.reload();//刷新页面
                    });
                } else {
                    layer.msg('教室添加失败，请稍后再试！', {
                        icon: 0,
                        time: 1000, //1秒关闭（如果不配置，默认是3秒）
                    }, function () {
                        // parent.layer.closeAll('iframe');
                        let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                    });
                }
            }, "text");
        });


    });
</script>
</body>
</html>